#include "include/syscall.h"
#include "include/global.h"
#include "include/tty.h"
#include "include/misc.h"
extern TTY tty_table[NR_CONSOLES];
int sys_call_get_ticks() {
    return ticks;
}
int sys_write(char * buf, int len, int dump,PROCESS* p_proc)
{
    tty_write(&tty_table[p_proc->nr_tty], buf, len);
    return 0;
}


int sys_sendrec(int function, int src_dest, MESSAGE *m, PROCESS *p)
{
    assert(k_reenter == 0); //没发生中断重入
    
    int ret = 0;
    int caller = proc2pid(p);
    MESSAGE *mla = (MESSAGE*) va2la(caller, m);
    mla->source = caller;
    assert(mla->source != src_dest);
    
    if (function == SEND)
    {
        
        ret = msg_send(p, src_dest, m);
        if (ret != 0)
            return ret;
    }
    else if (function = RECEIVE) {
        msg_receive(p, src_dest, m);
        
    } 
    else {
        panic("{sys_sendrec invaild function}: %d",
            function);
    }
    return 0;
}